package ItemBased;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Writable;
import org.apache.hadoop.mapred.OutputCollector;
import org.apache.hadoop.mapred.Reporter;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;

public class GenerateCoOccurrences {

	public static class GenerateUserVectorMap
    extends Mapper<LongWritable, LongPairArrayWritable, LongPairWritable, LongPairWritable>{
	      
	    public void map(LongWritable key, LongPairArrayWritable value,
	    		OutputCollector<LongPairWritable, LongPairWritable> output, Reporter reporter
	                    ) throws IOException, InterruptedException {
	    	
	    	Writable[] array = value.get();
	    	
	    	for(int i = 0; i < array.length; i++){
	    		for(int j = (i + 1); j < array.length; j++){
	    			LongPairWritable p1 = (LongPairWritable) array[i];
	    			LongPairWritable p2 = (LongPairWritable) array[j];
	    			output.collect(new LongPairWritable(p1.getFirst(), p2.getFirst()), new LongPairWritable(p1.getSecond(), p2.getSecond()));
	    		}
	    	}
	    	
	    }
	}
	
	public static class GenerateUserVectorReduce
    extends Reducer<LongPairWritable, LongPairWritable, LongPairWritable, LongWritable>{
	      
	    public void reduce(LongWritable LongPairWritable, Iterator<LongPairWritable> values,
	    		OutputCollector<LongPairWritable, LongPairWritable> output, Reporter reporter
	                    ) throws IOException, InterruptedException {
	    	
	    	ArrayList<LongPairWritable> item1 = new ArrayList<LongPairWritable>();
	    	ArrayList<LongPairWritable> item2 = new ArrayList<LongPairWritable>();
	    	
	    	while(values.hasNext()){
	    		values.next();
	    	}
	    		
	    	
	    }
	}
	    
	    
	    
	    
	    
	    
	public static void main(String[] args) {
		

	}

}
